<?php 
/*
Plugin Name: BPDEV-GROUP-SIDEBAR
Plugin URI: http://buddypressdev.org/plugins/bpdev-group-sidebar/
Description: Add a widget-ready sidebar below the avatar in the groups before & not
Author: Nicola Greco
Version: 0.3
Author URI: http://nicolagreco.com

Copyright (c) 2009-2011, Nicola Greco (mail: notsecurity@gmail.com | website: http://nicolagreco.com).

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

define( 'BPDEV_GROUP_SIDEBAR_NAME' , 'BPDEV-GROUP-SIDEBAR' );
define( 'BPDEV_GROUP_SIDEBAR_VERSION' , '0.3' );

add_action( 'bp_home_theme_functions' , 'bpdev_groups_sidebar_register' );
add_action( 'bp_member_theme_functions' , 'bpdev_groups_sidebar_register' );

add_action( 'bpdev_widget_groups_before' , 'bpdev_groups_widgetize_before' , 2 );
add_action( 'bpdev_widget_groups_after' , 'bpdev_groups_widgetize_after' , 2 );

function bpdev_groups_widgetize_before() {

	if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'groups-before' ) ) :

	?>
		<div class="info-group"><h4>Widget-Area</h4>
			<a href="http://buddypressdev.org/plugins/bpdev-groups-sidebar" title="Add sidebar to BuddyPress">BPDEV-GROUPS-SIDEBAR</a> is successfully installed. If you are the admin, add something in the sidebar or <a href="/wp-admin/widgets.php?show=&sidebar=groups-before">just click here to do it</a>. Remember to say thanks to <a href="http://nicolagreco.com" title="BuddyPress Developer">Nicola Greco</a>.
		</div>
	<?php endif;

	bpdev_groups_sidebar_credits( 'groups-before' );

}
function bpdev_groups_widgetize_after() {

	if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'groups-after' ) ) :

	?>
		<div class="info-group"><h4>Widget-Area</h4>
			<a href="http://bp-dev.org/projects/#widgets" title="Add sidebar to BuddyPress">BPDEV-GROUPS-SIDEBAR</a> is successfully installed. If you are the admin, add something in the sidebar or <a href="/wp-admin/widgets.php?show=&sidebar=groups-after">just click here to do it</a>. Remember to say thanks to <a href="http://nicolagreco.com" title="BuddyPress Developer">Nicola Greco</a>.
		</div>
	<?php endif;

	bpdev_groups_sidebar_credits( 'groups-after' );

}

function bpdev_groups_sidebar_register() {

	if ( function_exists( 'register_sidebar' ) )
		register_sidebar(array(
			'name' => 'Groups After',
			'id' => 'groups-after',
			'before_widget' => '<div class="info-group">',
			'after_widget' => '</div>',
			'before_title' => '<h4>',
			'after_title' => '</h4>'
		));

	if ( function_exists( 'register_sidebar' ) )
		register_sidebar(array(
			'name' => 'Groups Before',
			'id' => 'groups-before',
			'before_widget' => '<div class="info-group">',
			'after_widget' => '</div>',
			'before_title' => '<h4>',
			'after_title' => '</h4>'
		));

}

function bpdev_groups_sidebar_credits($sidebar) {

	if( is_site_admin() ) {

	?>
		<div class="generic-button"><a class="edit" title="Edit Sidebar" href="/wp-admin/widgets.php?show=&sidebar=<?php echo $sidebar; ?>">Edit Sidebar</a></div>
	<?php } ?>
		<div class="clear"></div>
<!--		<div class="generic-button"><a href="http://buddypressdev.org/plugins/bpdev-groups-sidebar" title="Add a sidebar in member-theme in BuddyPress">by BP-DEV.org</a></div>-->
			
	<?php

}
?>